/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author TAN
 */
public class Connect {
    	private	String Host="";
	private	String UserName="";
	private	String Pass="";
	private	String DataBase="";
	private String Port="";	
	private	Connection connect=null;
	//private	CallableStatement proc_stmt;
	//private	ResultSet result=null;
     public Connect(String User ,String Pass,String port,String DataBase,String Host)
    {
        UserName=User;
        this.Pass=Pass;
        Port=port;
        this.DataBase=DataBase;
        this.Host=Host;
        
    }
    protected Connection GetConnect(){
         try {
             if(this.connect==null)
             {
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
          UserName = "sa";
          Pass = "123456789";
            String url =  "jdbc:sqlserver://"+Host+":"+ Port+";databaseName="+DataBase+";";
            this.connect = DriverManager.getConnection(url+"user="+UserName+";password="+Pass);// (url+"user="+UserName+";password="+Pass);
             }
        }catch (Exception ex) {
            //System.out.println("Khong The Ket Noi SQL");
            ex.printStackTrace();
        }
         return this.connect;
    }
   
                 public void Close() 
		{
			
			try
                        {
			if(this.connect!=null && ! this.connect.isClosed())
			{
				this.connect.close();
				this.connect=null;
			}

                        }catch(SQLException ex)
                        {
                            ;
                        }
		}
                
		}               
  


